﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace FiberRMS.DAL.AlarmManager
{
    /// <summary>
    /// 数据访问类ALARM_RESOURCE。
    /// </summary>
    public class ALARM_RESOURCE
    {
        public ALARM_RESOURCE()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string RESOURCEID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ALARM_RESOURCE");
            strSql.Append(" where RESOURCEID=:RESOURCEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":RESOURCEID", OracleType.VarChar,50)};
            parameters[0].Value = RESOURCEID;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(FiberRMS.Model.AlarmManager.ALARM_RESOURCE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ALARM_RESOURCE(");
            strSql.Append("RESOURCEID,RESOURCECNNAME,RESOURCENAME)");
            strSql.Append(" values (");
            strSql.Append(":RESOURCEID,:RESOURCECNNAME,:RESOURCENAME)");
            OracleParameter[] parameters = {
					new OracleParameter(":RESOURCEID", OracleType.VarChar,10),
					new OracleParameter(":RESOURCECNNAME", OracleType.VarChar,50),
					new OracleParameter(":RESOURCENAME", OracleType.VarChar,50)};
            parameters[0].Value = model.RESOURCEID;
            parameters[1].Value = model.RESOURCECNNAME;
            parameters[2].Value = model.RESOURCENAME;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(FiberRMS.Model.AlarmManager.ALARM_RESOURCE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ALARM_RESOURCE set ");
            strSql.Append("RESOURCECNNAME=:RESOURCECNNAME,");
            strSql.Append("RESOURCENAME=:RESOURCENAME");
            strSql.Append(" where RESOURCEID=:RESOURCEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":RESOURCEID", OracleType.VarChar,10),
					new OracleParameter(":RESOURCECNNAME", OracleType.VarChar,50),
					new OracleParameter(":RESOURCENAME", OracleType.VarChar,50)};
            parameters[0].Value = model.RESOURCEID;
            parameters[1].Value = model.RESOURCECNNAME;
            parameters[2].Value = model.RESOURCENAME;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string RESOURCEID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete ALARM_RESOURCE ");
            strSql.Append(" where RESOURCEID=:RESOURCEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":RESOURCEID", OracleType.VarChar,50)};
            parameters[0].Value = RESOURCEID;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FiberRMS.Model.AlarmManager.ALARM_RESOURCE GetModel(string RESOURCEID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RESOURCEID,RESOURCECNNAME,RESOURCENAME from ALARM_RESOURCE ");
            strSql.Append(" where RESOURCEID=:RESOURCEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":RESOURCEID", OracleType.VarChar,50)};
            parameters[0].Value = RESOURCEID;

            FiberRMS.Model.AlarmManager.ALARM_RESOURCE model = new FiberRMS.Model.AlarmManager.ALARM_RESOURCE();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.RESOURCEID = ds.Tables[0].Rows[0]["RESOURCEID"].ToString();
                model.RESOURCECNNAME = ds.Tables[0].Rows[0]["RESOURCECNNAME"].ToString();
                model.RESOURCENAME = ds.Tables[0].Rows[0]["RESOURCENAME"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RESOURCEID,RESOURCECNNAME,RESOURCENAME ");
            strSql.Append(" FROM ALARM_RESOURCE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "ALARM_RESOURCE";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

